package com.vue.api.util;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.util.StringUtils;

import com.vue.api.entity.Page;

public class PageUtil {
	
	
	/**
	 * 集成数据
	 * @param <T>
	 * @param page
	 * @return
	 */
	public static <T>Map<String, Object> getVuePageData(Page<T> page){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("data", page.getResult()); //数据内容
		map.put("total", page.getTotalCount()); //总数据条数
		map.put("current", page.getPageNo()); //当前页
		map.put("size", page.getResult()==null?0:page.getResult().size()); //当前页数据
		return map;
	}
	/**
	 * 获取page对象 接受当前页和每页页数
	 * @param <T>
	 * @param request
	 * @return page对象
	 */
	public static <T> Page<T> getVuePage(HttpServletRequest request){
		int pageNo=1;	//当前页码
		int pageSize=20;	//每页行数
		
		if(!StringUtils.isEmpty(request.getParameter("pageNo")))
			pageNo=Integer.valueOf(request.getParameter("pageNo"));
		if(!StringUtils.isEmpty(request.getParameter("pageSize")))
			pageSize=Integer.valueOf(request.getParameter("pageSize"));
		
		return new Page<T> (pageNo, pageSize);
	}
}
